/**
 * Changes:
 * -Todo un poco
 * -The method throws an Exception.
 */

package eventReservationServer.eventServerGateway;

public class EventServerGatewayFactory
{

	/**
	 * ADD your code here; this class must be a SINGLETON String serviceUri =
	 * ip, port and name of the service String serverTech = technology of the
	 * server, 'corba' or 'ws'
	 */

	// Referencia al singleton
	private static EventServerGatewayFactory singleton = null;

	// Constructor privado
	private EventServerGatewayFactory()
	{
	}

	// Método de acceso a la clase
	public static EventServerGatewayFactory getSingleton()
	{
		if (singleton != null)
			return singleton;
		else
		{
			singleton = new EventServerGatewayFactory();
			return singleton;
		}
	}

	/**
	 * Método del singleton
	 * 
	 * Lo modifico para recibir todos los parámetros del documento XML
	 * 
	 * @param serverName
	 * @param serverIp
	 * @param serverPort
	 * @param serverTech
	 * @return
	 * @throws Exception
	 */
	public IEventServerGateway getEventServerGateway(String serverName, String serverIp, String serverPort, String serverTech) throws Exception
	{
		IEventServerGateway the_gateway = null;

		if (serverTech.equals("corba"))
			the_gateway = new CorbaEventServerGateway(serverName, serverIp, serverPort);
		else if (serverTech.equals("jms"))
			the_gateway = new JMSEventServerGateway();
		else if (serverTech.equals("ws"))
			the_gateway = new WSEventServerGateway();
		else
			throw new Exception("The requested server technology is not available.");

		return the_gateway;
	}
}
